package com.msh.starter.ip.analysis.inteface;

import com.msh.frame.client.exception.ServerException;
import com.msh.starter.ip.analysis.model.IpLocation;

import java.net.InetAddress;
import java.net.UnknownHostException;

public interface IIpCountry {
    IpLocation ipCountry(String ip);


    default IpLocation domainCountry(String domain){
        try {
            InetAddress address = InetAddress.getByName(domain);
            String hostAddress = address.getHostAddress();
            return ipCountry(hostAddress);
        } catch (UnknownHostException e) {
            throw new ServerException("域名解析失败: " + domain);
        }
    }
}
